package leetcode.weekly.week323;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

//Solution2Test
public class Solution2 {

	public int longestSquareStreak(int[] nums) {
		Arrays.sort(nums);
		Map<Integer, Integer> cnts = new HashMap<>();
		int ans = -1;
		for (int i = nums.length - 1; i >= 0; i--) {
			int num = nums[i];
			long nn = 1l * num * num;
			int cur = 1;
			if (nn <= Integer.MAX_VALUE) {
				cur = cnts.getOrDefault((int) nn, 0) + 1;
			}
			ans = Math.max(ans, cur);
			cnts.put(num, cur);
		}
		return ans < 2 ? -1 : ans;
	}

}
